//
//  LMMainViewController.swift
//  weibo项目
//
//  Created by apple on 16/7/20.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class LMMainViewController: UITabBarController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = LMTabBar()
        tabBar.shDelegate = self
        
        tabBar.closure = {
            print("按钮点击")
        }
        
        // 只读属性
        //self.tabBar = tabBar
        // 通过kvc 设置
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(LMHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(LMMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(LMDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(LMProfileViewController(), title: "我", imgName: "tabbar_profile")
        
    }
    /// 添加子控制器
    ///
    /// - parameter vc:      子控制器
    /// - parameter title:   名字
    /// - parameter imgName: 图片名字
    func addChildViewController(vc:UIViewController, title: String, imgName: String) {
        // 设置导航title
        //        vc.navigationItem.title = title
        //        // 设置tabbar title
        //        vc.tabBarItem.title = title
        vc.title = title
        // 设置图片
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 选择渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 设置颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        // 添加子控制器
        addChildViewController(UINavigationController(rootViewController: vc))
    }
    
}
// MARK: - SHTabBarDelegate
extension LMMainViewController: LMTabBarDelegate {
    func composeButtonClick() {
        print("按钮🔘")
    }

}
